﻿// // ******************************************************************
// //       /\ /|       @file       LanguageQueryHandler.cs
// //       \ V/        @brief      await29
// //       | "")       @author     Await, 285283010@qq.com
// //       /  |
// //      /  \\        @Modified   2024-12-28 20:12
// //    *(__\_\        @Copyright  Copyright (c) , 2024-12-25 18:12 Await
// // ******************************************************************

using AutomaticSubtitles.Contracts.Dto;
using AutomaticSubtitles.Contracts.Entity;
using AutomaticSubtitles.Service.Application.Language.Queries;
using AutomaticSubtitles.Service.Domain.Config;
using AutomaticSubtitles.Service.Infrastructure.Localization;

namespace AutomaticSubtitles.Service.Application.Language;

public class LanguageQueryHandler(ILanguageRepository repository, LocalizationManager _localizationManager) : BaseAutoService
{
    [EventHandler]
    public void GetUserDataQuery(GetListLanguageQuery query)
    {
        var list = LocalizationManager.GetLocalizationOptions();
        query.Result = list.MapToList<LocalizationOption<string>>();
        //GlobalVariableEnumConfiguration.LanguageEnum
        // var localizationOptions = new List<LocalizationOption<int>>();
        // Enum.GetValues(typeof(GlobalVariableEnumConfiguration.LanguageEnum)).Cast<GlobalVariableEnumConfiguration.LanguageEnum>().ToList().ForEach(x =>
        // {
        //     // localizationOptions.Add(new LocalizationOption(x.FindByAttribute<GlobalVariableEnumConfiguration.LanguageEnum,DescriptionAttribute>(), x.ToString()));
        //     localizationOptions.Add(new LocalizationOption<int>(x.FindByAttribute<GlobalVariableEnumConfiguration.LanguageEnum, DescriptionAttribute>()!.Description, (int)x));
        // });
        // query.Result = localizationOptions;
    }

    [EventHandler]
    public async Task Handler(GetLanguageKeyDataQuery query)
    {
        var autoLanguages = await repository.GetListAsync(x => true);
        query.Result = autoLanguages.ToDictionary(x => x.Key.ToString(), x => x.IsSkip);
    }

    [EventHandler]
    public async Task Handler(GetLanguageListDataQuery query)
    {
        var autoLanguages = await repository.GetListAsync(x => true);
        query.Result = autoLanguages.MapToList<LanguageDto>();
    }
}